From: robertl Date: Sat, 5 Jun 2010 22:02:39 +0000 (+0000) Subject: Add 'faketime' option to track filter with test cases and doc. X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~17^2~24 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=7972d1737983446d74eb22d81859b68508b7c831;p=gpsbabel.git Add 'faketime' option to track filter with test cases and doc. --- diff --git a/reference/track/trackfilter_faketime.gpx b/reference/track/trackfilter_faketime.gpx new file mode 100644 index 000000000..bdbb1316a --- /dev/null +++ b/reference/track/trackfilter_faketime.gpx @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/reference/track/trackfilter_faketime.txt b/reference/track/trackfilter_faketime.txt new file mode 100644 index 000000000..f9aff17fc --- /dev/null +++ b/reference/track/trackfilter_faketime.txt @@ -0,0 +1,4 @@ +lat, lon, date +36, -87 +36, -87, 2008-04-17 +36, -87 diff --git a/reference/track/trackfilter_faketime_forced.gpx b/reference/track/trackfilter_faketime_forced.gpx new file mode 100644 index 000000000..b215439da --- /dev/null +++ b/reference/track/trackfilter_faketime_forced.gpx @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/testo.d/classic-2.test b/testo.d/classic-2.test index 79acbafdf..9dba60b2b 100755 --- a/testo.d/classic-2.test +++ b/testo.d/classic-2.test @@ -342,21 +342,6 @@ compare ${TMPDIR}/vitosmt.gpx ${REFERENCE}/vitosmt.gpx gpsbabel -t -i vitosmt -f ${REFERENCE}/vitosmt.smt -o gpx -F ${TMPDIR}/vitosmt_t.gpx compare ${TMPDIR}/vitosmt_t.gpx ${REFERENCE}/track/vitosmt_t.gpx -# -# tracks filter tests -# - -rm -f ${TMPDIR}/trackfilter* - -gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,split,title="LOG-%Y%m%d" -o gpx -F ${TMPDIR}/trackfilter.gpx -compare ${TMPDIR}/trackfilter.gpx ${REFERENCE}/track/trackfilter.gpx - -gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,split,sdistance=0.1k -o gpx -F ${TMPDIR}/trackfilter2.gpx -compare ${TMPDIR}/trackfilter2.gpx ${REFERENCE}/track/trackfilter-sdistance.gpx - -gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,sdistance=0.1k,split=5m,title=%Y%m%d -o gpx -F ${TMPDIR}/trackfilter-sdistance2.gpx -compare ${TMPDIR}/trackfilter-sdistance2.gpx ${REFERENCE}/track/trackfilter-sdistance2.gpx - # # Map&Guide Motorrad Routenplaner .bcr files test # diff --git a/testo.d/track.test b/testo.d/track.test new file mode 100644 index 000000000..65bdf11ba --- /dev/null +++ b/testo.d/track.test @@ -0,0 +1,21 @@ +# +# tracks filter tests +# + +rm -f ${TMPDIR}/trackfilter* + +gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,split,title="LOG-%Y%m%d" -o gpx -F ${TMPDIR}/trackfilter.gpx +compare ${TMPDIR}/trackfilter.gpx ${REFERENCE}/track/trackfilter.gpx + +gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,split,sdistance=0.1k -o gpx -F ${TMPDIR}/trackfilter2.gpx +compare ${TMPDIR}/trackfilter2.gpx ${REFERENCE}/track/trackfilter-sdistance.gpx + +gpsbabel -t -i gpx -f ${REFERENCE}/track/trackfilter.gpx -x track,pack,sdistance=0.1k,split=5m,title=%Y%m%d -o gpx -F ${TMPDIR}/trackfilter-sdistance2.gpx +compare ${TMPDIR}/trackfilter-sdistance2.gpx ${REFERENCE}/track/trackfilter-sdistance2.gpx + +# Exercise the 'faketime' filter. The middle of the three points has +# time so we can exercise the 'forced' option, too. +gpsbabel -t -i unicsv -f ${REFERENCE}/track/trackfilter_faketime.txt -x track,faketime=20100506060000+5 -o gpx -F ${TMPDIR}/ft.gpx +compare ${REFERENCE}/track/trackfilter_faketime.gpx ${TMPDIR}/ft.gpx +gpsbabel -t -i unicsv -f ${REFERENCE}/track/trackfilter_faketime.txt -x track,faketime=f20100506060000+5 -o gpx -F ${TMPDIR}/ftf.gpx +compare ${REFERENCE}/track/trackfilter_faketime_forced.gpx ${TMPDIR}/ftf.gpx diff --git a/trackfilter.c b/trackfilter.c index bdc4551cc..11f687521 100644 --- a/trackfilter.c +++ b/trackfilter.c @@ -33,6 +33,7 @@ 2007-01-08: if not really needed disable check for valid timestamps (based on patch from Vladimir Kondratiev) 2007-07-26: Allow 'range' together with trackpoints without timestamp + 2010-06-02: Add specified timestamp to each trackpoint (added by sven_luzar) */ #include @@ -59,6 +60,7 @@ #define TRACKFILTER_SPEED_OPTION "speed" #define TRACKFILTER_SEG2TRK_OPTION "seg2trk" #define TRACKFILTER_TRK2SEG_OPTION "trk2seg" +#define TRACKFILTER_FAKETIME_OPTION "faketime" #undef TRACKF_DBG @@ -76,6 +78,7 @@ static char *opt_speed = NULL; static char *opt_name = NULL; static char *opt_seg2trk = NULL; static char *opt_trk2seg = NULL; +static char *opt_faketime = NULL; static arglist_t trackfilter_args[] = { @@ -117,6 +120,9 @@ arglist_t trackfilter_args[] = { {TRACKFILTER_TRK2SEG_OPTION, &opt_trk2seg, "Merge tracks inserting segment separators at boundaries", NULL, ARGTYPE_BOOL, ARG_NOMINMAX }, + {TRACKFILTER_FAKETIME_OPTION, &opt_faketime, + "Add specified timestamp to each trackpoint", + NULL, ARGTYPE_STRING, ARG_NOMINMAX}, ARG_TERMINATOR }; @@ -973,6 +979,101 @@ trackfilter_trk2seg(void) track_ct = 1; } +/******************************************************************************* +* option: "faketime" +*******************************************************************************/ + +typedef struct faketime_s +{ + time_t start; + int step; + int force; +} faketime_t; + +static faketime_t +trackfilter_faketime_check(const char *timestr) +{ + int i, j; + char fmtstart[20]; + char fmtstep[20]; + char c; + const char *cin; + struct tm time; + int timeparse = 1; + faketime_t result; + result.force = 0; + + i = j = 0; + strncpy(fmtstart, "00000101000000", sizeof(fmtstart)); + strncpy(fmtstep, "00000000000000", sizeof(fmtstep)); + cin = timestr; + + while ((c = *cin++)) + { + if (c=='f') { + result.force = 1; + continue; + } + + if (c!='+' && isdigit(c) == 0) + fatal(MYNAME "-faketime: invalid character \"%c\"!\n", c); + + if (timeparse) { + if ((c == '+')) { + fmtstart[i++] = '\0'; + timeparse = 0; + } else { + if (fmtstart[i] == '\0') fatal(MYNAME "-faketime: parameter too long \"%s\"!\n", timestr); + fmtstart[i++] = c; + } + } else { + if (fmtstep[j] == '\0') fatal(MYNAME "-faketime: parameter too long \"%s\"!\n", timestr); + fmtstep[j++] = c; + } + } + fmtstep[j++] = '\0'; + + cin = strptime(fmtstart, "%Y%m%d%H%M%S", &time); + result.step = atoi(fmtstep); + if ((cin != NULL) && (*cin != '\0')) + fatal(MYNAME "-faketime-check: Invalid time stamp (stopped at %s of %s)!\n", cin, fmtstart); + + result.start = mkgmtime(&time); + return result; +} + +static int +trackfilter_faketime(void) /* returns number of track points left after filtering */ +{ + faketime_t faketime; + + queue *elem, *tmp; + int i, dropped, inside = 0; + + if (opt_faketime != 0) + faketime = trackfilter_faketime_check(opt_faketime); + + dropped = inside = 0; + + for (i = 0; i < track_ct; i++) + { + route_head *track = track_list[i].track; + + QUEUE_FOR_EACH((queue *)&track->waypoint_list, elem, tmp) + { + waypoint *wpt = (waypoint *)elem; + + if (opt_faketime != 0 && (wpt->creation_time == 0 || faketime.force)) { + wpt->creation_time = faketime.start; + faketime.start += faketime.step; + } + } + } + + return track_pts - dropped; +} + + /******************************************************************************* * global cb's *******************************************************************************/ @@ -1058,6 +1159,20 @@ trackfilter_process(void) if ( !opts ) return; } + if ((opt_faketime != NULL)) + { + opts--; + + trackfilter_faketime(); + + if (opts == 0) return; + + trackfilter_deinit(); /* reinitialize */ + trackfilter_init(NULL); + + if (track_ct == 0) return; /* no more track(s), no more fun */ + } + if ((opt_stop != NULL) || (opt_start != NULL)) { if (opt_start != NULL) opts--; diff --git a/xmldoc/filters/options/track-faketime.xml b/xmldoc/filters/options/track-faketime.xml new file mode 100644 index 000000000..15955ffc2 --- /dev/null +++ b/xmldoc/filters/options/track-faketime.xml @@ -0,0 +1,41 @@ + +This option assigns a time value to each trackpoint. + + +The value of this option must be in the form of fYYYYMMDDHHMMSS+SS. + + +The parameter f (force) is optional and means that the time value of each trackpoint is replaced. +If f is not specified, the time value of each trackpoint is only replaced when the trackpoint contains no time value. + + +YYYYMMDDHHMMSS is the pattern for the timestamp and is required. + + +The plus sign is the delimiter between the timestamp and the step time in seconds. +The first trackpoint receives the time value of the timestamp and +each following trackpoint receives the timestamp incremented by the step time. +The specification of the steptime is optional. + + +The parameter was added because some software products (e.g. garmin training center) +require a time value for each trackpoint. + + +Replace time values of a track + +Replace all time values with new time values. +Start at the 5 th of July, 2010 at 8 PM and +increment 2 seconds between each trackpoint: + +gpsbabel -i kml -f in.kml -x track,faketime=f20100705200000+2 -o gtrnctr -F out.tcx + + +Add time values to a track + +Add a time value to a trackpoint, if the trackpoint contains no time value. +Start at the 6 th of May, 2010 at 6 AM and +increment 5 seconds between each trackpoint: + +gpsbabel -i kml -f in.kml -x track,faketime=20100506060000+5 -o gtrnctr -F out.tcx +